/**
 * 
 * Copyright (C) 2011 Cody Stoutenburg . All rights reserved.
 *
 *       This program is free software; you can redistribute it and/or
 *       modify it under the terms of the GNU Lesser General Public License
 *       as published by the Free Software Foundation; either version 2.1
 *       of the License, or (at your option) any later version.
 *
 *       This program is distributed in the hope that it will be useful,
 *       but WITHOUT ANY WARRANTY; without even the implied warranty of
 *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *       GNU Lesser General Public License for more details.
 *
 *       You should have received a copy of the GNU Lesser General Public License
 *       along with this program; if not, write to the Free Software
 *       Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
 * 
 */
package ca.usherbrooke.goal;

import java.util.ArrayList;

import ca.usherbrooke.model.entity.IEntityModel;
import ca.usherbrooke.model.equipment.EquipmentModel;
import ca.usherbrooke.model.world.IWorldModel;
import ca.usherbrooke.tools.position.Vector2D;

/**
 * @author Cody Stoutenburg
 * 
 */
public class TakeObjectGoal extends IGoal {
	private static String GOAL_NAME = TakeObjectGoal.class.getName();

	public static String getGeneralDescription() {
		return "<html>"
				+ "<p><b>Description:</b></p>"
				+ "<p>Ask to take an equipment. </p> "
				+ "<p style=\"color:green\">The goal is solve when the entity take the equipment.</p>"
				+ "<p style=\"color:red\"> The goal never fail </p>" + "<br/>"
				+ "<b>Params:</b><br/> equipmentId(long) </p>" + "</html>";
	}

	private Long guidEquipment;

	@Override
	protected void initGoal(String args) {
		String[] argument = args.split(IGoal.ARGS_SEPARATOR);

		this.guidEquipment = Long.valueOf(argument[argsCount + 0]);
	}

	@Override
	public Boolean verifyGoalSolve(IWorldModel world) {
		Boolean isSolve = false;

		IEntityModel ent = world.getEntity(this.getEntity());
		EquipmentModel eq = world.getEquipment(guidEquipment);
		if (eq != null && ent != null) {
			isSolve = ent.equals(eq.getHolder());
		}
		return isSolve;
	}

	@Override
	public Boolean verifyGoalFail(IWorldModel world) {
		return false;
	}

	@Override
	public Float calculateEstimatedDistance(IWorldModel world) {
		Float dist = Float.MAX_VALUE;
		EquipmentModel eq = world.getEquipment(guidEquipment);
		if (eq != null) {
			Vector2D objectPos = eq.getPosition();
			dist = world.getEntity(this.getEntity()).getPosition()
					.getSquaredDistance(objectPos);
		}
		return dist;
	}

	public Long getEquipment() {
		return guidEquipment;
	}

	@Override
	public ArrayList<Float> getValues() {
		ArrayList<Float> values = new ArrayList<Float>();
		values.add(guidEquipment.floatValue());
		return values;
	}

	@Override
	public String getName() {
		return GOAL_NAME;
	}

	@Override
	public String getDescription() {
		return "Prendre l'objet: " + guidEquipment;
	}
}
